﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ReportBubbleViewModel.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Defines the ReportBubbleViewModel type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.Silverlight.MVVM.ViewModels
{
    #region Using statements

    using System.Windows.Input;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight.Messaging;

    using Spenta.StreetCare.Silverlight.MVVM.Messages;
    using Spenta.StreetCare.Silverlight.StreetCareAPI;

    #endregion

    /// <summary>
    /// Defines the ReportBubbleViewModel type
    /// </summary>
    public class ReportBubbleViewModel : BaseViewModel
    {
        /// <summary>
        /// Private store for the report
        /// </summary>
        private Report report;

        /// <summary>
        /// Initializes a new instance of the <see cref="ReportBubbleViewModel"/> class.
        /// </summary>
        public ReportBubbleViewModel()
        {
            Messenger.Default.Register<SelectReportMessage>(this, message => Report = message.Report);
        }

        /// <summary>
        /// Gets or sets the report.
        /// </summary>
        /// <value>
        /// The report.
        /// </value>
        public Report Report
        {
             get
             {
                 return this.report;
             }

            set
            {
                this.report = value;
                this.RaisePropertyChanged("Report");
            }
        }

        /// <summary>
        /// Gets the close bubble command reference.
        /// </summary>
        public ICommand CloseBubbleCommand
        {
            get
            {
                return new RelayCommand(this.CloseBubble);
            }
        }

        /// <summary>
        /// Gets the open report command reference.
        /// </summary>
        public ICommand OpenReportCommand
        {
            get
            {
                return new RelayCommand(this.OpenReport);
            }
        }

        /// <summary>
        /// Handles the close bubble command.
        /// </summary>
        public void CloseBubble()
        {
            Messenger.Default.Send(new CloseBubbleMessage());
        }

        /// <summary>
        /// Handles the open report command.
        /// </summary>
        public void OpenReport()
        {
            Messenger.Default.Send(new CloseBubbleMessage());
            Messenger.Default.Send(new OpenReportMessage { Report = this.report });
        }
    }
}
